package com.app.utils;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;

import com.app.base.tool.BaseFragment;

/**
 * 作者：lblbh on 2017/8/3 10:28
 * 邮箱：lanbuhan@163.com
 * 功能：TODO
 */
public class NetBroadcastReceiver extends BroadcastReceiver {

    public NetEvevt evevt = BaseFragment.evevt;

    @Override
    public void onReceive(Context context, Intent intent) {
        // 如果相等的话就说明网络状态发生了变化
        if (intent.getAction().equals(ConnectivityManager.CONNECTIVITY_ACTION)) {
            int netWorkState = CommonUtil.isNetworkAvailable(context);
            // 接口回调传过去状态的类型
            if(evevt != null)
                evevt.onNetChange(netWorkState);
        }
    }


    public interface NetEvevt {
        /**
         * 0-没有网 1-wifi 2-手机网络
         * @param netMobile
         */
        public void onNetChange(int netMobile);
    }
}